﻿Imports UI

Public Class FrminiciarSesion


    Private Sub Label1_Click(sender As Object, e As EventArgs)

    End Sub
    Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs)

    End Sub


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None 'Elimina los bordes del formulario
        Me.WindowState = FormWindowState.Maximized 'Maximiza el formulario
    End Sub


    Private Sub Button2_Click(sender As Object, e As EventArgs)
        Me.Close()
    End Sub


    Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
        Dim correoElectronico As String
        Dim contrasenna As String
        Dim camposRequeridos As Boolean = False
        Dim datosCorrectos As Boolean = False

        correoElectronico = txtxCorreo.Text
        contrasenna = txtxContrasena.Text

        For Each x As Panel In panelPrincipal.Controls.OfType(Of Panel)()
            For Each txt As TextBox In x.Controls.OfType(Of TextBox)()
                If txt.Text.Length < 1 Then
                    Dim msk As New Label
                    msk.Text = "Campo requerido"
                    msk.Location = New Point(x.Location.X + x.Width + 8, x.Location.Y + 10)
                    msk.ForeColor = Color.DarkOrange
                    msk.Visible = True
                    msk.Width = 300
                    panelPrincipal.Controls.Add(msk)
                    labelArray.Add(msk)
                Else
                    camposRequeridos = True
                End If
            Next
        Next

        If camposRequeridos = True Then
            datosCorrectos = objGestorUsuario.comprobarUsuario(correoElectronico, contrasenna)

            If datosCorrectos <> True Then
                'revisar esto un toque despues con respecto a los datos
                informar()
            Else
                UsuarioActivo = objGestorUsuario.iniciarSesion(correoElectronico)
                abrirPermisos()
                Dim Frm As New FrmPrincipal
                Frm.Show()
                Me.Hide()

            End If
        End If
    End Sub

    Private Sub abrirPermisos()
        list = objGestorUsuario.obtenerPermisos(UsuarioActivo.IdRol)
    End Sub

    Private Sub limpiarPanel()
        For Each txt As Label In labelArray
            txt.Visible = False
        Next
    End Sub

    Public Sub informar()
        Dim datosInvalidos As New Label
        datosInvalidos.Text = "Carnet o contraseña inválidos"
        datosInvalidos.Location = New Point(Panel4.Location.X + 100, Panel4.Location.Y + 50)
        datosInvalidos.Visible = True
        datosInvalidos.ForeColor = Color.DarkOrange
        datosInvalidos.Width = 1000
        datosInvalidos.Height = 300
        labelArray.Add(datosInvalidos)
        panelPrincipal.Controls.Add(datosInvalidos)
    End Sub

    Private Sub txtxCorreo_Click(sender As Object, e As EventArgs) Handles txtxCorreo.Click
        limpiarPanel()
    End Sub
    Private Sub txtxContrasena_Click(sender As Object, e As EventArgs) Handles txtxContrasena.Click
        limpiarPanel()
    End Sub

    Private Sub recuperarContrasena_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs)

    End Sub

    Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click
        Me.Hide()
        FrmrecuperarContraseña.Show()
    End Sub
End Class
